#ifndef H_RIFF
#define H_RIFF
#include <stdint.h>
#include <string.h>

struct RIFF {
	//12 byte riff header
	char chunkid[4]; //"RIFF"
	uint32_t chunksize; //essentially filesize-8 because this value starts counting 8 bytes in
	char format[4]; //this contains the text "WAVE"

	//WAVE chunk.. contains 2 subchunks fmt and data
	char subchunkid[4]; //contains the text "fmt "
	uint32_t subchunksize; //how big the fmt subchunk is ... for PCM this is 16
	uint16_t audioformat; //this is 1 for raw or something else for compressed
	uint16_t channels; //number of channels
	uint32_t hz; //the samplerate
	uint32_t byterate; //SampleRate * NumChannels * BitsPerSample/8
	uint16_t blockalign; //NumChannels * BitsPerSample/8
	uint16_t bps; //bits per sample
	//end fmt unless not PCM

	//data subchunk
	char subchunkid2[4]; //contains text "data"
	uint32_t subchunksize2; //how big the rest of the file is
	//end header...
	//data goes here... but we let the program concatenate this struct to the data

	RIFF();
	RIFF(uint32_t samplerate, uint16_t nchannels);

	//~RIFF(){ } would the the deconstructor if we needed one btw
};

RIFF::RIFF(){
	//constructor for RIFF
	//make the strings
	strncpy(chunkid, "RIFF", 4);
	strncpy(format, "WAVE", 4);
	strncpy(subchunkid, "fmt ", 4);
	strncpy(subchunkid2, "data", 4);

	subchunksize = 16;
	audioformat = 1;
	channels = 2;
	hz = 44100;
	bps = 16;
	byterate = hz*channels*(bps/8);
	blockalign = channels*(bps/8);
}

RIFF::RIFF(uint32_t samplerate, uint16_t nchannels){
	//c++ doesn't let you call a constructor within another constructor
	//but does allow you to overload constructors
	//make the strings
	strncpy(chunkid, "RIFF", 4);
	strncpy(format, "WAVE", 4);
	strncpy(subchunkid, "fmt ", 4);
	strncpy(subchunkid2, "data", 4);

	subchunksize = 16;
	audioformat = 1;
	channels = nchannels;
	hz = samplerate;
	bps = 16;
	byterate = hz*channels*(bps/8);
	blockalign = channels*(bps/8);
}

#endif
